package sites.manager.common.config;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

/**
 * 参数校验的配置
 * 
 * @author zyg
 * 2022年2月10日 下午8:35:45
 */
@Configuration
public class ValidatorConfig {

	@Bean
    public MethodValidationPostProcessor methodValidationPostProcessor() {
        MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor();
        postProcessor.setValidator(validator());
        return postProcessor;
    }
	
	@Bean
	public Validator validator() {
		ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
				.configure()
				//.addProperty("hibernate.validator.fail_fast", "true")
				.failFast(true)
				.buildValidatorFactory();
		Validator validator = validatorFactory.getValidator();
		return validator;
	} 
	
}
